<template>
    <div>
      <a-button type="primary" @click="exportExcel">导出 Excel</a-button>
    </div>
  </template>
  
  <script lang="ts">
    import { defineComponent } from 'vue';
    import XLSX from 'xlsx-style';
    import { Button } from 'ant-design-vue';
  
    export default defineComponent({
      components: {
        'a-button': Button,
      },
      methods: {
        exportExcel() {
          const wb = XLSX.utils.book_new();
          const ws = XLSX.utils.aoa_to_sheet([
            ["Hello", "World"],
            [1, 2]
          ]);
  
          // 添加样式
          ws['A1']['s'] = {
            font: {
              sz: 14,
              bold: true,
              color: { rgb: "FFFFAA00" }
            },
            fill: {
              fgColor: { rgb: "FFFFAA00" }
            }
          };
  
          // 添加工作表到工作薄
          XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
  
          // 导出Excel文件
          XLSX.writeFile(wb, "output.xlsx");
        }
      }
    });
  </script>

  <style lang="less"></style>